package kr.saeildamil.androidstudty.ch19;

import kr.saeildamil.androidstudty.R;
import android.R.integer;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

public class LongTime extends Activity {
	int mValue;
	TextView mText;
	ProgressDialog mProgress;
	boolean mQuit;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch19_longtime);
		mText=(TextView) findViewById(R.id.ch19_longtime_count);
	}
	
	public void mOnClick(View v){
		mValue=0;
		showDialog(0);
		mQuit=false;
		mHandler.sendEmptyMessage(0);
	}
	
	
	Handler mHandler=new Handler(){
		public void handleMessage(android.os.Message msg) {
			mValue++;
			mText.setText(Integer.toString(mValue));
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if(mValue<100 && mQuit==false){
				mProgress.setProgress(mValue);
				mHandler.sendEmptyMessage(0);
			}else{
				dismissDialog(0);
			}
		}
	};
}
